/*
 * @descripttion: 
 * @author: chaoa
 * @version: 1.0.0
 * @Date: 2021-10-19 17:11:45
 * @history: 
 */
// components/goods/goods.js
const componentBehavior = require('../../js/common/ComponentBehavior')

Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {

    imgDomain:{type:String,value:''},
    link: { type: String },
    pic: { type: String, value: '/assets/images/img.png' },
    name: { type: String },
    market: { type: Array },
    label:{type: Array},
    DisplayTags:{type: Array},
    spec: { type: String },
    buynum: { type: String },
    unit: { type: String },
    auxUnit:{ type: String },
    //是否需要初始检测
    isInitTest: {
      type: Boolean,
      value: false
    },
    /**最小值允许为0 */
    minAllowZero: {
      type: Boolean,
      value: true
    },
    iscard: {
      type: Boolean,
      value: false
    },
    translated: {
      type: Number,
      value: 1
    },
    baseUnit:{type:String},
    index:{type:Number},//索引
    quantityDigits: {type: Number,value: 2},//数量显示小数位数
    priceDigits:{type:Number,value:2},//价格显示小数位数
    hasSmMarket: { type: Boolean, value: false },
    hasTrash: { type: Boolean, value: false },//是否显示回收站
    hasNumAct: { type: Boolean, value: false },//是否显示实际数量
    isSingle: { type: Number, value: 0 },//是否单规格
    cartCount: { type: Number, value: 0 },//文本框中显示数量
    cid:{type: Number, value: 0},//
    primaryId: { type: Number, value: 0 },//唯一Id
    isScanty:{type:Boolean,value:false},//是否开启缺货登记
    zeroStockBuy:{type:Number,value:0},//开启零库存
    buyLowerLimit:{type:Number,value:0},//购买下限
    buyUpperLimit:{type:Number,value:0},//购买上限
    IsBuy: { type: Boolean, value: false },
    stock: { type: Number, value: 0 },//库存数量
    sStock: { type: Number, value: 0 },//源库存数量
    sBuyLowerLimit:{type:Number,value:0},//源购买下限
    sBuyUpperLimit:{type:Number,value:0},//源购买上限
    shelved:{type:Number,value:1},//上架状态 
    isShowInvalid:{type:Boolean,value:false},//是否显示验证货品状态
    isWait:{type:Boolean,value:false},//是否需要等待（加载完后才能跳转)
    purchasePower: { type: Boolean, value: true },//是否有购买权限
    multipleBuy:{type:Number,value:0},//倍数
    cartType:{type:Number,value: 0},//状态
    nums:{type:Number,value: 0},//length
    multiple:{type:Number,value: 0},//套餐数量
    types:{type:String},//类型
    iptType:{type:Boolean,value:false},//是否显示input
    style:{type:Boolean,value:false},//样式修改
    cartMax: { // 购物车页面重新计算的最大数量
      type: Number,
      value: 0
    },
    itemType: { // 当前item的类型，orderOffineRetreat：erp订单退换货详情
      type: String,
      value: ''
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    baseNum:0,
  },
  behaviors: [componentBehavior],

  observers: {
    'translated, buynum' () {
      let {
        buynum,
        translated,
        quantityDigits
      } = this.data
      if (translated > 1) {
        this.setData({
          baseNum: (buynum * translated).toFixed(quantityDigits)
        })
      }
    }
  },
  
  /**
   * 组件的方法列表
   */
  methods: {
    /*移除 */
    onRemove:function(e){
      var id = e.currentTarget.dataset.id;
      this.triggerEvent("onRemove", {id:id});
    },

    //数量改变
    onNumChage(e) {
      e.detail.primaryId = this.data.primaryId;
      this.triggerEvent("onNumChage", e.detail);
    },
    onTranslatedChange(e){
      e.detail.primaryId = this.data.primaryId;
      this.triggerEvent("onTranslatedChange", e.detail);
    },
    //弹出缺货登记的层
    onShowScanty(e) {
      this.triggerEvent("onShowScanty", e.currentTarget.dataset.idx);
    },
    //点击商品主图
    onClickImage(e){
      this.triggerEvent("onClickImage", e.detail);
    }
  }
})
